import { take, put, fork,takeEvery } from 'redux-saga/effects';
import * as actionTypes from './action-types';
function delay(ms) {
  return new Promise(resolve => {
    setTimeout(resolve, ms);
  });
}
function* workerSaga() {
  yield delay(1000);
  console.log('start');
  yield put({
    type: actionTypes.ADD
  });
}

function* rootSaga() {
  //监听每一次向仓库派发的ASYNC_ADD动作，派发之后会开启一个新的子saga运行workerSaga
  //watcherSaga  while true   take fork workerSaga
  yield takeEvery(actionTypes.ASYNC_ADD,workerSaga);
  //takeEvery是非阻塞的调用
  console.log('done')
}
export default rootSaga;